/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package radiostation;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import model.DBManager;
import model.PlayList;
import model.Song;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/**
 *
 * @author sky
 */
public class ListJFrame extends javax.swing.JFrame {

    /**
     * Creates new form ListJFrame
     */
    public ListJFrame() {
        em = DBManager.em;
        if (!em.getTransaction().isActive()) {
            em.getTransaction().begin();
        }
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        query1 = java.beans.Beans.isDesignTime() ? null : em.createQuery("select p from PlayList p");
        queryList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(query1.getResultList());
        newJBtn = new javax.swing.JButton();
        editJBtn = new javax.swing.JButton();
        deleteJBtn = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        goHomeJBtn = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        exportJBtn = new javax.swing.JButton();
        importJBtn = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("RadioStation");

        newJBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/list-add.png"))); // NOI18N
        newJBtn.setText("Δημιουργία");
        newJBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newJBtnActionPerformed(evt);
            }
        });

        editJBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/document-edit.png"))); // NOI18N
        editJBtn.setText("Ενημέρωση");
        editJBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editJBtnActionPerformed(evt);
            }
        });

        deleteJBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/list-remove.png"))); // NOI18N
        deleteJBtn.setText("Διαγραφή");
        deleteJBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteJBtnActionPerformed(evt);
            }
        });

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/media-optical-audio.png"))); // NOI18N
        jLabel1.setText("Λίστα τραγουδιών");

        goHomeJBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/edit-undo.png"))); // NOI18N
        goHomeJBtn.setText("Επιστροφή στο Μενού");
        goHomeJBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                goHomeJBtnActionPerformed(evt);
            }
        });

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, queryList, jTable1);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${playListId}"));
        columnBinding.setColumnName("Id");
        columnBinding.setColumnClass(Long.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${playListName}"));
        columnBinding.setColumnName("Περιγραφή");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${playListDate}"));
        columnBinding.setColumnName("Ημερομηνία");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable1);
        if (jTable1.getColumnModel().getColumnCount() > 0) {
            jTable1.getColumnModel().getColumn(0).setMaxWidth(60);
            jTable1.getColumnModel().getColumn(2).setPreferredWidth(150);
            jTable1.getColumnModel().getColumn(2).setMaxWidth(200);
        }

        exportJBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/text-xml.png"))); // NOI18N
        exportJBtn.setText("Εξαγωγή σε XML");
        exportJBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportJBtnActionPerformed(evt);
            }
        });

        importJBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/text-xml.png"))); // NOI18N
        importJBtn.setText("Εισαγωγή από XML");
        importJBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                importJBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(newJBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(deleteJBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(editJBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                        .addComponent(goHomeJBtn))
                    .addComponent(jScrollPane2)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(importJBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(exportJBtn)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(exportJBtn)
                    .addComponent(importJBtn))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newJBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(editJBtn)
                    .addComponent(deleteJBtn)
                    .addComponent(goHomeJBtn))
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void newJBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newJBtnActionPerformed
        //pat3code: spyros Δημιουργία νέας λίστας
        l = new PlayList();
        l.setPlayListName("");
        l.setPlayListDate(new Date());
        em.persist(l);
        EditListJFrame elf = new EditListJFrame(l);
        elf.setVisible(true);
        thisFrame = this;
        thisFrame.setEnabled(false);
        //pat3group: Listener---------------------------------
        elf.addWindowListener(new WindowListener() {
            @Override
            public void windowClosed(WindowEvent arg0) {
                System.out.println("Window close event occur");
                if (arg0 instanceof MyWindowEvent) {
                    if (((MyWindowEvent) arg0).exitAndSave) {
                        em.persist(l);
                        queryList.add(l);
                        em.getTransaction().commit();
                        em.getTransaction().begin();
                        int row = queryList.size() - 1;
                        jTable1.setRowSelectionInterval(row, row);
                        jTable1.scrollRectToVisible(jTable1.getCellRect(row, 0, true));
                    } else {
                        java.util.Collection data = query1.getResultList();
                        for (Object entity : data) {
                            em.refresh(entity);
                        }
                        queryList.clear();
                        queryList.addAll(data);
                    }
                }
                thisFrame.setEnabled(true);
            }

            @Override
            public void windowActivated(WindowEvent arg0) {
                System.out.println("Window Activated");
            }

            @Override
            public void windowClosing(WindowEvent arg0) {
                System.out.println("Window Closing");
            }

            @Override
            public void windowDeactivated(WindowEvent arg0) {
                System.out.println("Window Deactivated");
            }

            @Override
            public void windowDeiconified(WindowEvent arg0) {
                System.out.println("Window Deiconified");
            }

            @Override
            public void windowIconified(WindowEvent arg0) {
                System.out.println("Window Iconified");
            }

            @Override
            public void windowOpened(WindowEvent arg0) {
                System.out.println("Window Opened");
            }
        });
        //----------------------------------------------------
    }//GEN-LAST:event_newJBtnActionPerformed

    private void goHomeJBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goHomeJBtnActionPerformed
        // TODO add your handling code here:
        try {
            System.out.println("disposing frame");
            dispose();
        } catch (Exception e) {
            System.out.println(e);
        }
    }//GEN-LAST:event_goHomeJBtnActionPerformed

    private void deleteJBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteJBtnActionPerformed
        s = jTable1.getSelectedRow();
        if (s >= 0) {
            PlayList list4del = queryList.get(jTable1.convertRowIndexToModel(s));
            queryList.remove(list4del);
            em.remove(list4del);
            em.getTransaction().commit();
            em.getTransaction().begin();
        }
    }//GEN-LAST:event_deleteJBtnActionPerformed

    private void editJBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editJBtnActionPerformed
        // TODO add your handling code here:
        s = jTable1.getSelectedRow();
        if (s >= 0) {
            l = queryList.get(s);
            EditListJFrame elf = new EditListJFrame(l);
            elf.setVisible(true);
            thisFrame = this;
            thisFrame.setEnabled(false);
            elf.addWindowListener(new WindowListener() {
                public void windowClosed(WindowEvent arg0) {
                    System.out.println("Window close event occur");
                    if (arg0 instanceof MyWindowEvent) {
                        if (((MyWindowEvent) arg0).exitAndSave) {
                            System.out.println(l);
                            em.merge(l);
                            queryList.set(s, l);
                            em.getTransaction().commit();
                            em.getTransaction().begin();
                        } else {
                            em.getTransaction().rollback();
                            em.getTransaction().begin();
                            java.util.Collection data = query1.getResultList();
                            for (Object entity : data) {
                                em.refresh(entity);
                            }
                            queryList.clear();
                            queryList.addAll(data);
                        }
                    }
                    thisFrame.setEnabled(true);
                }

                public void windowActivated(WindowEvent arg0) {
                    System.out.println("Window Activated");
                }

                public void windowClosing(WindowEvent arg0) {
                    System.out.println("Window Closing");
                }

                public void windowDeactivated(WindowEvent arg0) {
                    System.out.println("Window Deactivated");
                }

                public void windowDeiconified(WindowEvent arg0) {
                    System.out.println("Window Deiconified");
                }

                public void windowIconified(WindowEvent arg0) {
                    System.out.println("Window Iconified");
                }

                public void windowOpened(WindowEvent arg0) {
                    System.out.println("Window Opened");
                }
            });
        }
    }//GEN-LAST:event_editJBtnActionPerformed

    private void exportJBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportJBtnActionPerformed
        // TODO add your handling code here:
        //  pat3group: sky - Δημιουργία XML
        s = jTable1.getSelectedRow();
        if (s >= 0) {
            try {
                PlayList exportList = queryList.get(s);
                DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
                Document doc = docBuilder.newDocument();
                Element playlistTag = doc.createElement("playlist");
                doc.appendChild(playlistTag);
                Attr attr = doc.createAttribute("id");
                attr.setValue(exportList.getPlayListId().toString());
                playlistTag.setAttributeNode(attr);
                Element titleTag = doc.createElement("title");
                titleTag.appendChild(doc.createTextNode(exportList.getPlayListName()));
                playlistTag.appendChild(titleTag);
                Element dateTag = doc.createElement("date");
                SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
                dateTag.appendChild(doc.createTextNode(df.format(exportList.getPlayListDate())));
                playlistTag.appendChild(dateTag);
                Query queryXML = em.createQuery("SELECT pl FROM PlayList pl WHERE pl.playListId=:id").setParameter("id", exportList.getPlayListId());
                List<PlayList> resultsXML = queryXML.getResultList();
                for (PlayList i : resultsXML) {
                    List<Song> songs = i.getSongList();
                    for (Song j : songs) {
                        Element lsong = doc.createElement("song"); // δημιουργώ ένα song
                        playlistTag.appendChild(lsong); // τον συνδέω με τον τρέχοντα κόμβο
                        attr = doc.createAttribute("id"); // ο κόμβος αυτός έχει ένα χαρακτηριστικό το id
                        attr.setValue(j.getSongId().toString()); // σαν τιμή θα πάρει id του song
                        lsong.setAttributeNode(attr);
                        //Συνεχίζω βάζοντας κι άλλα στοιχεία, τίτλο κτλ...
                        //το artist & group τα κάνω με trycatch για να αποφεύγω εκπλήξεις με ανύπαρκτα
                        //αντικείμενα. θα μπορούσα να τα γράφω σε κοινό tag και 
                        //να αλλάζω μόνο το createTextNode, αλλά μου αρέσει καλύτερα
                        //έτσι. άλλα στοιχεία δε προσθέτω. αν θέλουμε προσθέτουμε 
                        //με τον ίδιο τρόπο.
                        Element title = doc.createElement("title");
                        title.appendChild(doc.createTextNode(j.getSongTitle()));
                        lsong.appendChild(title);
                        Element duration = doc.createElement("duration");
                        duration.appendChild(doc.createTextNode(Long.toString(j.getSongDuration())));
                        lsong.appendChild(duration);
                        //συνθέτω το όνομα του καλλιτέχνη αφού δε με ενδιαφέρει να
                        //έχω ένα ένα τα πεδία χώρια. βγαίνει πιο όμορφο.
                        try {
                            Element art = doc.createElement("artist");
                            art.appendChild(doc.createTextNode(
                                    j.getAlbumId().getArtistId().getArtistFname() + " "
                                    + j.getAlbumId().getArtistId().getArtistLname() + ", ("
                                    + j.getAlbumId().getArtistId().getArtistArtname() + ")"));
                            lsong.appendChild(art);
                        } catch (Exception e) {
                        }
                        try {
                            Element grp = doc.createElement("group");
                            grp.appendChild(doc.createTextNode(j.getAlbumId().getAlbumMusicGroupId().getMusicGroupName()));
                            lsong.appendChild(grp);
                        } catch (Exception e) {
                        }

                    }
                }

                // pat3group: sky - πλαίσιο file open στο default φάκέλο (XMLUserFiles).
                JFileChooser browse = new JFileChooser("XMLUserFiles");
                //  pat3group: sky - δείξε default μόνο xml αρχεία.
                FileNameExtensionFilter filter = new FileNameExtensionFilter("*.xml", "xml");
                browse.addChoosableFileFilter(filter);
                browse.setFileFilter(filter);
                if (browse.showSaveDialog(browse) == JFileChooser.APPROVE_OPTION) {
                    // γράφω όλα τα παραπάνω σε ένα αρχείο xml
                    TransformerFactory transformerFactory = TransformerFactory.newInstance();
                    Transformer transformer = transformerFactory.newTransformer();
                    DOMSource source = new DOMSource(doc);
                    StreamResult result;
                    result = new StreamResult(new FileWriter(browse.getSelectedFile()));
                    transformer.transform(source, result);
                    System.out.println("File saved!");
                }
            } catch (ParserConfigurationException pce) {
                pce.printStackTrace();
            } catch (TransformerException tfe) {
                tfe.printStackTrace();
            } catch (IOException ex) {
                Logger.getLogger(EditListJFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_exportJBtnActionPerformed

    private void importJBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importJBtnActionPerformed
        // pat3group: sky - πλαίσιο file open στο default φάκέλο (XMLUserFiles).
        JFileChooser browse = new JFileChooser("XMLUserFiles");
        //  pat3group: sky - δείξε default μόνο xml αρχεία.
        FileNameExtensionFilter filter = new FileNameExtensionFilter("*.xml", "xml");
        browse.addChoosableFileFilter(filter);
        browse.setFileFilter(filter);
        /*  pat3group: sky - Εισαγωγή από XML.
         Διαβάζω από το Document Object Model του xml τα id των τραγουδιών,
         φτιάχνω μια νέα άδεια λίστα και γράφω στη βάση συσχετίσεις
         Θεωρώ ότι η Λίστα αποτελείται από τραγούδια που υπάρχουν μέσα στο σύστημα
         για λόγους απλότητας. Οπότε το μόνο που χρειάζεται για να εισαχθεί η λίστα
         είναι να μπούν τα στοιχεία της και οι συσχετίσεις στη βάση.
         */
        if (browse.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            File file = browse.getSelectedFile();
            try {
                Document dom;
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                dom = db.parse(file);
                Element root = dom.getDocumentElement();    //Πιάνω το tag <playlist> 
                long xmlSongId = 0;
                l = new PlayList();
                l.setPlayListName(root.getElementsByTagName("title").item(0).getTextContent());
                SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
                String dateXML = root.getElementsByTagName("date").item(0).getTextContent();
                try {
                    l.setPlayListDate(df.parse(dateXML));
                } catch (ParseException ex) {
                    Logger.getLogger(ListJFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
                em.persist(l);
                queryList.add(l);
                em.getTransaction().commit();
                em.getTransaction().begin();
                String qStr;
                NodeList nl = root.getElementsByTagName("song");
                if (nl != null && nl.getLength() > 0) {
                    for (int i = 0; i < nl.getLength(); i++) {
                        Element el = (Element) nl.item(i);
                        xmlSongId = Long.parseLong(el.getAttribute("id")); //ID Τραγουδιού
                        qStr = "INSERT INTO RADIO.SONG_PLAY_LIST (PLAY_LIST_ID, SONG_ID) \n"
                                + "VALUES ( " + l.getPlayListId() + " , " + xmlSongId + " )";
                        System.out.println(qStr);
                        em.createNativeQuery(qStr).executeUpdate();
                    }

                    em.getTransaction().commit();
                    em.getTransaction().begin();
                    java.util.Collection data = query1.getResultList();
                    for (Object entity : data) {
                        em.refresh(entity);
                    }
                    queryList.clear();
                    queryList.addAll(data);
                }
            } catch (ParserConfigurationException pce) {
                pce.printStackTrace();
            } catch (SAXException se) {
                se.printStackTrace();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    }//GEN-LAST:event_importJBtnActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        // pat3group: sky edit με διπλό κλικ πάνω στη γραμμή του πίνακα.
        if (evt.getClickCount() > 1) {
            editJBtnActionPerformed(null);
        }
    }//GEN-LAST:event_jTable1MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ListJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ListJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ListJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ListJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ListJFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton deleteJBtn;
    private javax.swing.JButton editJBtn;
    private javax.swing.JButton exportJBtn;
    private javax.swing.JButton goHomeJBtn;
    private javax.swing.JButton importJBtn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton newJBtn;
    private javax.persistence.Query query1;
    private java.util.List<PlayList> queryList;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    EntityManager em;
    JFrame thisFrame;
    PlayList l;
    int s;
}
